package cn.zyq.ykb.service.sys.impl;


import cn.zyq.ykb.beans.sys.SysAdmin;
import cn.zyq.ykb.beans.sys.SysLogininfor;
import cn.zyq.ykb.mapper.sys.SysLogininforMapper;
import cn.zyq.ykb.service.sys.SysLogininforService;
import cn.zyq.ykb.system.common.BaseService;
import cn.zyq.ykb.system.common.PageParam;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 系统访问记录
 * 2023-05-12 20:14:08
 */

@Slf4j
@Service
public class SysLogininforServiceImpl extends BaseService implements SysLogininforService {
    @Autowired
    private SysLogininforMapper sysLogininforMapper;


    @Override
    public PageInfo<SysLogininfor> list(PageParam pageParam, SysAdmin admin) {
        PageHelper.startPage(pageParam.getPage(), pageParam.getPageSize());
        List<SysLogininfor> dbList = this.sysLogininforMapper.list(pageParam.getKv());
        return new PageInfo<>(dbList);
    }

    @Override
    public void add(SysLogininfor param, SysAdmin admin) {
        this.setCreateBaseData(param, admin);
        this.sysLogininforMapper.insertSelective(param);
    }

    @Override
    public void update(SysLogininfor param, SysAdmin admin) {
        Integer id = param.getSysLogininforID();
        this.setUpdateBaseData(param, admin);
        this.sysLogininforMapper.updateByPrimaryKeySelective(param);
    }

    @Override
    public void del(String serviceID, SysAdmin admin) {
        SysLogininfor dbInfo = this.detail(serviceID);
        Integer id = dbInfo.getSysLogininforID();
        this.deleteLogic(id, admin, this.sysLogininforMapper);
    }

    @Override
    public SysLogininfor detail(String serviceID, SysAdmin admin) {
        return this.detail(serviceID);
    }

    @Override
    public SysLogininfor detail(String serviceID) {
        SysLogininfor dbInfo = this.getByServiceID(serviceID, SysLogininfor.class, this.sysLogininforMapper);
        this.checkLogicExist(dbInfo);
        return dbInfo;
    }

    /**
     * 新增系统登录日志
     *
     * @param logininfor 访问日志对象
     */
    @Override
    public void insertLogininfor(SysLogininfor logininfor)
    {
        sysLogininforMapper.insertSelective(logininfor);
    }

    /**
     * 查询系统登录日志集合
     *
     * @param pageParam 访问日志对象
     * @return 登录记录集合
     */
    @Override
    public List<SysLogininfor> selectLogininforList(PageParam pageParam)
    {
        return sysLogininforMapper.selectLogininforList(pageParam.getKv());
    }

    /**
     * 批量删除系统登录日志
     *
     * @param infoIds 需要删除的登录日志ID
     * @return 结果
     */
    @Override
    public int deleteLogininforByIds(Integer[] infoIds)
    {
        int i = 0;
        for (Integer infoId : infoIds) {
           i += sysLogininforMapper.deleteByPrimaryKey(infoId);
        }
        return i;
    }

    /**
     * 清空系统登录日志
     */
    @Override
    public void cleanLogininfor()
    {
        sysLogininforMapper.cleanLogininfor();
    }
}
